
#从get地址中替换的内容：
#000100.SZ -> STOCKCODE

sample_code = "000100.SZ"

TimePeriod = {
    1: "-03-31",
    2: "-06-30",
    3: "-09-30",
    4: "-12-31"
}


def make_timestr(FromYear=2024,ToYear=2014,ReportTime=4):
    result = ""
    datanum = 0
    for i in range(ToYear,FromYear + 1):
        result = "%2C%27" + str(i) + TimePeriod[ReportTime] + "%27" + result
        datanum += 1
    #print (datanum)
    return (result[3:],datanum)

# 年报主要指标：
url_main_base = "https://datacenter.eastmoney.com/securities/api/data/get?type=RPT_F10_FINANCE_MAINFINADATA&sty=APP_F10_MAINFINADATA&quoteColumns=&filter=(SECUCODE%3D%22STOCKCODE%22)(REPORT_TYPE%3D%22%E5%B9%B4%E6%8A%A5%22)&p=1&ps=NUM&sr=-1&st=REPORT_DATE&source=HSF10"
def make_url_mian(STOCKCODE="000100.SZ", datanum=10):
    result = ""
    result = url_main_base.replace("STOCKCODE",STOCKCODE).replace("ps=NUM","ps="+str(datanum))
    return result

# 资产负债表：
url_zichan_base = "https://datacenter.eastmoney.com/securities/api/data/get?type=RPT_F10_FINANCE_GBALANCE&sty=F10_FINANCE_GBALANCE&filter=(SECUCODE%3D%22STOCKCODE%22)(REPORT_DATE%20in%20(TIMESTR))&p=1&ps=NUM&sr=-1&st=REPORT_DATE&source=HSF10"
def make_url_zichan(STOCKCODE="000100.SZ", FromYear=2024, ToYear=2014, ReportTime=4):
    #timestr = "%272023-12-31%27%2C%272022-12-31%27%2C%272021-12-31%27%2C%272020-12-31%27%2C%272019-12-31%27%2C%272018-12-31%27%2C%272017-12-31%27%2C%272016-12-31%27%2C%272015-12-31%27%2C%272014-12-31%27"
    timestr,datanum = make_timestr(FromYear,ToYear,ReportTime)
    result = url_zichan_base.replace("STOCKCODE",STOCKCODE)
    result = result.replace("TIMESTR", timestr)
    result = result.replace("ps=NUM","ps="+str(datanum))
    return result

#利润表
url_lirun_base = "https://datacenter.eastmoney.com/securities/api/data/get?type=RPT_F10_FINANCE_GINCOME&sty=APP_F10_GINCOME&filter=(SECUCODE%3D%22STOCKCODE%22)(REPORT_DATE%20in%20(TIMESTR))&p=1&ps=NUM&sr=-1&st=REPORT_DATE&source=HSF10"
def make_url_lirun(STOCKCODE="000100.SZ", FromYear=2024, ToYear=2014, ReportTime=4):
    #timestr = "%272023-12-31%27%2C%272022-12-31%27%2C%272021-12-31%27%2C%272020-12-31%27%2C%272019-12-31%27%2C%272018-12-31%27%2C%272017-12-31%27%2C%272016-12-31%27%2C%272015-12-31%27%2C%272014-12-31%27"
    timestr,datanum = make_timestr(FromYear,ToYear,ReportTime)
    result = url_lirun_base.replace("STOCKCODE",STOCKCODE)
    result = result.replace("TIMESTR", timestr)
    result = result.replace("ps=NUM","ps="+str(datanum))
    return result

#现金流量表
url_cash_base = "https://datacenter.eastmoney.com/securities/api/data/get?type=RPT_F10_FINANCE_GCASHFLOW&sty=APP_F10_GCASHFLOW&filter=(SECUCODE%3D%22STOCKCODE%22)(REPORT_DATE%20in%20(TIMESTR))&p=1&ps=NUM&sr=-1&st=REPORT_DATE&source=HSF10"
def make_url_cash(STOCKCODE="000100.SZ", FromYear=2024, ToYear=2014, ReportTime=4):
    #timestr = "%272023-12-31%27%2C%272022-12-31%27%2C%272021-12-31%27%2C%272020-12-31%27%2C%272019-12-31%27%2C%272018-12-31%27%2C%272017-12-31%27%2C%272016-12-31%27%2C%272015-12-31%27%2C%272014-12-31%27"
    timestr,datanum = make_timestr(FromYear,ToYear,ReportTime)
    result = url_cash_base.replace("STOCKCODE",STOCKCODE)
    result = result.replace("TIMESTR", timestr)
    result = result.replace("ps=NUM","ps="+str(datanum))
    return result

